/**
 * @FileName: main.cc
 * @Author: 李波(Edwin Lee)
 * @Date: 2024-04-21 12:23:18
 * @Version: 1.0
 * @Description: 
 */
#include "public.h"
#include "connection.h"
#include "commonConnectionPool.h"
#include <ctime>
#include <memory>
#include <iostream>
//#include <signal.h>
Logger& logger = Logger::getInstance();
//测试不使用连接池的效果
void test1();
//测试使用连接池的效果
void test2();

int main()
{
	logger.open();
	logger.info("main begin\n");
	clock_t begin = clock();
	test1();
	//test2();
	clock_t end =clock();
	cout<<"用时="<<(end-begin)<<endl;
	
	return 0;
}


void test1()
{
	for(int i=0; i<1000; ++i)
	{
		Connection conn;
		char sql[1024]={0};
		sprintf(sql,"insert into user(name,age,sex) values('%s',%d,'%s')","zhang san",20,"male");
		conn.connect("127.0.0.1", 3306, "edwin","aaa111", "chat");
		conn.update(sql);
	}
	return;
}

void test2()
{
	ConnectionPool& cnp = ConnectionPool::getInstance();
	for(int i=0; i<1000; ++i)
	{
		shared_ptr<Connection> conn = cnp.getConnection();
		if(conn==nullptr)
		{
			logger.fatal("cnp.getConnection failed\n");
			return;
		}

		char sql[1024]={0};
		sprintf(sql,"insert into user(name,age,sex) values('%s',%d,'%s')","zhang san",20,"male");
		conn->update(sql);	
	}
}
